using System;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace sla
{
    class SignalsManager
    {
        ArrayList signals;
        int signalsCount;
        ConnectionsManager connectionManager; 
        

        public SignalsManager(MainForm mainform, int numSignals, int signalsPannelHeight, int signalsPannelWidth)
        {
            signals = new ArrayList();
            
            
            // init rect with the initial location of the first signal (10 pixels from the panel in x and y direction)
            Rectangle rect = new Rectangle(10, 10, signalsPannelWidth-20, signalsPannelHeight / ((numSignals + 1) + ((numSignals + 1)*0 / 4)));
            for (int i = 0; i < numSignals; i++)
            {
                signals.Add(new Signal(mainform, "Signal_" + i.ToString(), rect));
                rect.Y += rect.Height + (0*rect.Height/4);
            }
            this.signalsCount = numSignals;

            connectionManager = new ConnectionsManager(this);
        }
        public void processNewCapture(int timeStamp, int signals)
        {
            int mask = 0x1;

            for (int i = 0; i < this.signalsCount; i++)
            {
                ((Signal)this.signals[i]).addNewSignalInfo(new SignalInfo(timeStamp, (signals & (mask << i)) >> i));
            }
        }

        public void RefreshAllSignal(float timePerDivision, int deltaX)
        {
            float currentTimeStamp;
            float newTimeStamp;
            Signal.UpdateDrawingParameters();
            currentTimeStamp = Signal.CurrentTimeStamp;
            newTimeStamp = Signal.PositionToTime(Signal.TimeToPosition(currentTimeStamp) + deltaX);
            Signal.TimePerDivisionInMicroSeconds = timePerDivision;

            Signal.CurrentTimeStamp = newTimeStamp;
            
            foreach (Signal signal in this.signals)
            {
                signal.refresh();
            }
        }
    }
}
